<?php
namespace App\Home\Controller;
use Library\Controller;
use Library\Model;
use Library\Request;
use Library\Response;

use Library\TestYun;

function object_array2($array) {
	if(is_object($array)) {
		$array = (array)$array;
	}if(is_array($array)) {
		foreach($array as $key=>$value) {
			$array[$key] = object_array2($value);
		}
	}
	return $array;
}


class Index extends Controller{
	
	public function __construct(Request $request,Response $response){
		
	}
	
	//测试
	public function index(){
// 		$this->assign('name','liming');
// 		$this->assign('year',23);
// 		$this->assign('company',['year'=>12,'name'=>['s'=>'liuyun']]);
	
		//取通讯录
	    $testyun=new TestYun('app');
	    $commlist=object_array2(json_decode(file_get_contents("comm.log")));
	   if($commlist){
	   	 $this->assign('commlist',$commlist[data]['persons']);
	   }else{
	   	$commlist=$testyun->getcomm();
	     if($commlist['success']==1){
	     	$this->assign('commlist',$commlist[data]['persons']);
	       file_put_contents("comm.log",json_encode($commlist));
	   	  }
	   }
	   if($_GET['stime'] && $_GET['etime']){
	   	
	   	$this->assign('stime',$_GET['stime']);
	   	$this->assign('etime',$_GET['etime']);
	   	$this->assign('openId',$_GET['openId']);
	   	
	   	$testyun=new TestYun('resGroupSecret');
	   
	   	$clock=$testyun->getclock($_GET['stime'],$_GET['etime'],$_GET[openId]);
	   	$clock_data=$clock['data'];
	   	foreach ($clock_data as &$val){
	   		$val['time']=date('Y--m-d H:i:s',$val['time']);
	   	}
	   	$this->assign('clock_data',$clock_data);
	   }
	  // $stime=$_GET['stime'];
	  // echo($stime);
	   
	  // 
	  $this->display();
	}
	
	
	
	//测试
	public function hello(){
		$this->assign('name','liming');
		$this->assign('year',23);
		$this->assign('company',['year'=>12,'name'=>['s'=>'liuyun']]);
		$this->display();
	}
	
	public function test(Model $user){
		$this->assign('user',$user);
		$this->display();
	}
	
	public function _show(){
		$this->display();
	}
}
